<?php
/**
 * WDC Like Dislike Component
 * @author Joomla web Developer <contact@adodis.com>
 * @link http://www.joomla-web-developer.com
**/


 // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

function com_install()
{
jimport('joomla.filesystem.path');
jimport('joomla.filesystem.file');

$db =& JFactory::getDBO();

$select = "SELECT element FROM #__plugins WHERE element='content_vote' ";
$db->setQuery($select);
$result = $db->loadResult();
	if($result!="content_vote"){
		$content = "INSERT INTO `#__plugins`(`name`,`element`,`folder`,`access`,`ordering`,`published`,`iscore`,`client_id`,`checked_out`,`checked_out_time`,`params`) Values('Content Vote','content_vote','content','0','0','1','0','0','0','','')";
		$db->setQuery($content);
		$db->query();
	}

	$select = "SELECT element FROM #__plugins WHERE element='likedislike' ";
	$db->setQuery($select);
	$result = $db->loadResult();
	if($result!="likedislike"){
		$editor = "INSERT INTO `#__plugins`(`name`,`element`,`folder`,`access`,`ordering`,`published`,`iscore`,`client_id`,`checked_out`,`checked_out_time`,`params`) Values('Like and Dislike','likedislike','editors-xtd','0','0','1','0','0','0','','')";
		$db->setQuery($editor);
		$db->query();
	}

			if(!JFolder::exists(JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'cimages')){
				JFolder::move(JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote'.DS.'cimages', JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'cimages');
			}

			$copy_file1 = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote'.DS.'content_vote.php';
			$paste_file1 = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'content_vote.php';
			if (!JFile::exists($paste_file1)){
				copy($copy_file1, $paste_file1);
			}else{
				JFile::delete(JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'content_vote.php');
				copy($copy_file1, $paste_file1);
			}

			 
			$delete_cvote_sql = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'cvote_sql.php';
			if (JFile::exists($delete_cvote_sql)){
					JFile::delete($delete_cvote_sql);
				 
			}	
	 
			$delete_style = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'style.css';
			if (JFile::exists($delete_style)){
				JFile::delete($delete_style);
			} 
			
			$copy_folder = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote'.DS.'wdc_assets';
			$paste_folder = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'wdc_assets';
			if(!JFolder::exists($paste_folder)){
				JFolder::move($copy_folder,$paste_folder);
			}else{
				JFolder::delete($paste_folder);
				JFolder::move($copy_folder,$paste_folder);		
			}
			
			$delete_folder = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'cimages';
			if(JFolder::exists($delete_folder)){
				JFolder::delete($delete_folder);
			}

			$copy_file4 = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'likedislike_editor'.DS.'likedislike.php';
			$paste_file4 = JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike.php';
			if (!JFile::exists($paste_file4)){
				copy($copy_file4, $paste_file4);
			}else{
				JFile::delete(JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike.php');
				copy($copy_file4, $paste_file4);
			}

			$copy_file5 = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'likedislike_editor'.DS.'likedislike_button.jpg';
			$paste_file5 = JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike_button.jpg';
			if (!JFile::exists($paste_file5)){
				copy($copy_file5, $paste_file5);
			}else{
				JFile::delete(JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike_button.jpg');
				copy($copy_file5, $paste_file5);
			}

			$copy_file6 = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'likedislike_editor'.DS.'likedislike.xml';
			$paste_file6 = JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike.xml';
			if (!JFile::exists($paste_file6)){
				copy($copy_file6, $paste_file6);
			}else{
				JFile::delete(JPATH_ROOT.DS.'plugins'.DS.'editors-xtd'.DS.'likedislike.xml');
				copy($copy_file6, $paste_file6);
			}

			$copy_file7 = JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote'.DS.'content_vote.xml';
			$paste_file7 = JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'content_vote.xml';
			if (!JFile::exists($paste_file7)){
				copy($copy_file7, $paste_file7);
			}else{
				JFile::delete(JPATH_ROOT.DS.'plugins'.DS.'content'.DS.'content_vote.xml');
				copy($copy_file7, $paste_file7);
			}



			if(JFolder::exists(JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote')){
				JFolder::delete(JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'content_vote');
			}

			if(JFolder::exists(JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'likedislike_editor')){
				JFolder::delete(JPATH_ROOT.DS.'components'.DS.'com_wdclikedislike'.DS.'likedislike_editor');
			}
}
?>